﻿using Emgu.CV.CvEnum;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OpenCvApplication.View.CommonView
{
    public partial class BlurParameterControl : UserControl
    {
        public BlurParameterControl()
        {
            InitializeComponent();

            foreach (Control item in this.Controls)
            {
                if (item is TrackBar trackBar)
                    trackBar.Scroll += trackBar_Scroll;
            }
        }
        private void trackBar_Scroll(object sender, EventArgs e)
        {
            RefreshShow();
            ValueChange?.Invoke(this, Args);
        }
        public Action<object, BlurFilterEventArgs> ValueChange { get; set; }
        private void BlurParameterControl_Load(object sender, EventArgs e)
        {
            ValueChange?.Invoke(this, Args);
        }

        private void cbPoint_CheckedChanged(object sender, EventArgs e)
        {
            CbPoint(!cbPoint.Checked);
            RefreshShow();
        }
        private void CbPoint(bool enabled)
        {
            tcbSigmaX.Enabled = tcbsigmaY.Enabled = enabled;
        }
        private void RefreshShow()
        {
            lblSizeWidth.Text = SizeWidth.ToString();
            lblSizeHeight.Text = SizeHeight.ToString();
            lblSigmaX.Text = X.ToString();
            lblsigmaY.Text = Y.ToString();
        }
        public int SizeWidth
        {
            get => tcbSizeWidth.Value;
        }
        public int SizeHeight
        {
            get => tcbSizeHeight.Value;
        }
        public int X
        {
            get => cbPoint.Checked ? -1 : tcbSigmaX.Value;
        }
        public int Y
        {
            get => cbPoint.Checked ? -1 : tcbsigmaY.Value;
        }
        public BlurFilterEventArgs Args
        {
            get => new BlurFilterEventArgs(SizeWidth, SizeHeight, X, Y);
        }
    }
    public class BlurFilterEventArgs : EventArgs
    {
        public BlurFilterEventArgs()
        {
        }
        public BlurFilterEventArgs(int sizeWidth, int sizeHeight, int x, int y) : this()
        {
            this.SizeWidth = sizeWidth;
            this.SizeHeight = sizeHeight;
            this.X = x;
            this.Y = y;
        }
        public int SizeWidth { get; set; }
        public int SizeHeight { get; set; }
        public int X { get; set; }
        public int Y { get; set; }
    }
}
